/*
 * (c) 2019 <tanghaifeng-gz@loongson.cn> <pengren.mcu@qq.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 *
 */

#ifndef __LS2H_DEV_REV2_1_CONFIG_H
#define __LS2H_DEV_REV2_1_CONFIG_H

#include <linux/sizes.h>
#include "loongson_bootmenu.h"

/* Loongson bootelf bootparam smbios */
#define CONFIG_SMBIOS_PRODUCT_NAME "Loongson 2H"
#define CONFIG_LOONGSON_BOOT_FIXUP
#define CONFIG_SMBIOS_MANUFACTURER "Loongson"

#define CONFIG_LOONGSON_BOARD_NAME "LS2H-DEV-REV2.1"

#define OSC_CLK			25000000 //LS2H使用25MHz晶振

#define CPU_CLOCK_RATE	800000000	/* 800 MHz clock for the MIPS core */
#define APB_CLOCK_RATE	125000000	/* 定义apb频率为125 MHz，目前固定为125MHz */
#define SBC_CLOCK_RATE	APB_CLOCK_RATE
#define CPU_TCLOCK_RATE CPU_CLOCK_RATE

#define CPU_TCLOCK_RATE CPU_CLOCK_RATE
#define CONFIG_SYS_MIPS_TIMER_FREQ  (CPU_TCLOCK_RATE / 2)
#define CONFIG_SYS_HZ   1000

/* memory */
#define CONFIG_SYS_SDRAM_BASE		0x80000000	/* Cached addr */
#define CONFIG_SYS_SDRAM_SIZE		SZ_2G
#define CONFIG_SYS_INIT_SP_OFFSET	0x00400000
#define CONFIG_SYS_LOAD_ADDR		0x83000000
#define FDT_LOAD_ADDR		0x8b000000
#define RAMDISK_START		0x88000000
#define RAMDISK_SIZE		0x02000000

/* DMA */
//#define CONFIG_DMA_COHERENT
//#define CONFIG_DMA_COHERENT_SIZE	(1 << 20)

/* Miscellaneous configurable options */
#define CONFIG_SYS_MAXARGS 64	/* max number of command args */
#define CONFIG_SYS_CBSIZE 512 /* Console I/O Buffer Size */

#define CONFIG_SYS_MONITOR_BASE	CONFIG_SYS_TEXT_BASE
//#define CONFIG_SYS_MONITOR_LEN		(192 << 10)
#define CONFIG_SYS_MALLOC_LEN	(28 * 1024 * 1024)

/* 串口打印信息，汇编调试 */
#define CONFIG_PRINTK
#ifndef CONFIG_DM_SERIAL
#define CONFIG_CPU_UART
#define CONFIG_CONS_INDEX	1
#define CONFIG_SYS_NS16550_SERIAL
#define CONFIG_SYS_NS16550_REG_SIZE	 1
#endif
#define CONFIG_SYS_NS16550_CLK	APB_CLOCK_RATE
#define CONFIG_SYS_NS16550_COM1	 0xbfe80000
#define UART_BASE_ADDR	CONFIG_SYS_NS16550_COM1

/* LS1X SPI Settings */
#ifdef CONFIG_LS1X_SPI
//#define CONFIG_LS1X_SPI1_ENABLE	/* 使用spi1控制器(复用设置), spi1控制器复用can，如果不使用spi1，最好把该选项关闭 */
#define CONFIG_SPI_CS
//#define CONFIG_SPI_CS_USED_GPIO
#endif

/* Environment settings */
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
#define CONFIG_ENV_SIZE			0x4000	/* 16KB */
#define CONFIG_ENV_SPI_CS		0
#define CONFIG_ENV_SPI_MAX_HZ	30000000
#define CONFIG_ENV_OFFSET		0xd0000	/* 根据分区大小修改，这里是SPI Flash uboot_env的偏移地址 */
#define CONFIG_ENV_SECT_SIZE	(4 << 10)
/*
 * Environment is right behind U-Boot in flash. Make sure U-Boot
 * doesn't grow into the environment area.
 */
#define CONFIG_BOARD_SIZE_LIMIT		CONFIG_ENV_OFFSET
#elif CONFIG_ENV_IS_IN_EEPROM
#define CONFIG_ENV_SIZE			0x800	/* 2KB */
#define CONFIG_ENV_OFFSET		0x0
#define CONFIG_ENV_EEPROM_IS_ON_I2C
#define CONFIG_SYS_DEF_EEPROM_ADDR	0x50 /* i2a slave addr */
#define CONFIG_BOARD_SIZE_LIMIT		0xd0000
#else
#define CONFIG_ENV_SIZE			0x800	/* 2KB */
#define CONFIG_ENV_OFFSET		0x0
#define CONFIG_BOARD_SIZE_LIMIT		0xd0000
#endif

/* NAND settings */
#ifdef CONFIG_NAND
#define CONFIG_SYS_NAND_ONFI_DETECTION
#define CONFIG_SYS_NAND_SELF_INIT
#define CONFIG_SYS_MAX_NAND_DEVICE	1
#define CONFIG_SYS_NAND_BASE	LS2X_NAND_BASE
#define NAND_LS1X_CS 0
#define NAND_LS1X_MAX_CHIPS 1
#define NAND_LS2K_DMACHAN 0
#define CONFIG_NAND_ECC_BCH
#endif

/* USB */
#ifdef CONFIG_USB_OHCI_HCD
#define CONFIG_USB_OHCI_NEW
#define CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS	8
#endif

/* Ethernet driver configuration */
#if defined(CONFIG_LOONGSON_GMAC) || defined(CONFIG_ETH_DESIGNWARE)
#define ENH_DESC //ls2x的gmac控制器需要把该宏定义打开
#define CONFIG_DW_GMAC_DEFAULT_DMA_PBL 4
#define CONFIG_DW_ALTDESCRIPTOR
#define PHY_ANEG_TIMEOUT	8000
#endif
#define CONFIG_NET_MULTI
#define CONFIG_NET_RETRY_COUNT          5

#define CONFIG_ETHADDR		08:00:3e:26:0a:5b
#define CONFIG_IPADDR		192.168.1.20
#define CONFIG_NETMASK		255.255.255.0
#define CONFIG_SERVERIP		192.168.1.2

/* Framebuffer and LCD */
#if defined(CONFIG_VIDEO_LS1X)
#define LS1X_DC0
//#define LS1X_DC0_USE_DEMODE
#define LS1X_DC1
//#define LS1X_DC1_USE_DEMODE
#define LS1X_DC_MAX 2
#endif
#if defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
#define VIDEO_FB_16BPP_WORD_SWAP
#define CONFIG_SPLASH_SCREEN
#define CONFIG_SPLASH_SCREEN_ALIGN
/* logo 设置 */
#define CONFIG_VIDEO_LOGO
#define CONFIG_VIDEO_BMP_RLE8
#define CONFIG_VIDEO_BMP_LOGO
#define CONFIG_BMP_16BPP
#define CONFIG_BMP_24BPP
#define CONFIG_BMP_32BPP
#endif

#ifdef CONFIG_VIDEO
#define CONSOLE_STDOUT_SETTINGS \
	"stdin=serial,usbkbd\0" \
	"stdout=serial\0" \
	"stderr=serial,vga\0"
#elif CONFIG_DM_VIDEO
#define CONSOLE_STDOUT_SETTINGS \
	"splashimage=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
	"stdin=serial,usbkbd\0" \
	"stdout=serial\0" \
	"stderr=serial,vidconsole\0"
#else
#define CONSOLE_STDOUT_SETTINGS \
	"stdin=serial\0" \
	"stdout=serial\0" \
	"stderr=serial\0"
#endif


#define	CONFIG_EXTRA_ENV_SETTINGS					\
	CONSOLE_STDOUT_SETTINGS \
	LOONGSON_BOOTMENU \
	"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
	"fdt_addr=" __stringify(FDT_LOAD_ADDR) "\0" \
	"rd_start=" __stringify(RAMDISK_START) "\0" \
	"rd_size=" __stringify(RAMDISK_SIZE) "\0" \
	"mtdids=" CONFIG_MTDIDS_DEFAULT "\0"					\
	"mtdparts=" CONFIG_MTDPARTS_DEFAULT "\0"				\
	"splashpos=m,m\0" \
	"video=" "VGA-1:1920x1080-32@60 video=VGA-2:1920x1080-32@60" "\0" \
	"panel0=" "vesa1280x1024@60" "\0" \
	"panel1=" "vesa1280x1024@60" "\0" \
	"root_dev=sda\0" \
	"syspart=1\0" \
	"update=1\0" \

#define CONFIG_SYS_BOOTM_LEN	SZ_64M

/* Boot beep */
#define BEEP_GPIO 0


/* ls2h ddr配置 */
#define SET_DDR_FREQ

#define DDR3_DIMM
#define LS2HMC
#define AUTO_DDR_CONFIG
#define DIMM_ID 0x54

#endif /* __LS2H_DEV_REV2_1_CONFIG_H */
